<template>
  <div class="consensus-activity-withdraw">
    <c-title :text="text"></c-title>
    <div class="head" v-if="type == 1||type==5">
      当前{{ yuan_name }}：{{ usable_yuan }}
      <template  v-if="(type == 1||type==5) && open==1">
        ，当前{{ yuan_withdraw_limit_name }}：{{yuan_withdraw_quota }}
      </template>
    </div>
    <div class="head" v-if="type == 3 || type==4 || type==6">当前{{income_name}}：{{income}}</div>
    <div class="head" v-else-if="type == 2">当前{{ yuan_withdraw_limit_name }}：{{ yuan_withdraw_quota }}</div>
    <div class="main">
      <div class="member" v-if="type == 2 || type==4">
        <span style="flex-shrink: 0;">受让人ID</span>
        <input type="text" v-model="uid" placeholder="请输入" />
      </div>
      <p class="left fz26">
        {{ type==1?`提现${yuan_name}`:(type==2||type==4)?'转让数量':(type == 3 || type==5)?'转入数量':`提现${income_name}` }}
      </p>
      <div class="content">
        <input type="text" v-model="count" @focus="onFocus" />
        <span  class="all" @click="all_handle">{{(type==1||type==6)?'全部提现':'全部'}}</span>
      </div>
      <p class="tips" v-if="type == 1||(type==5&&open==1)">需要扣除{{count}}{{yuan_withdraw_limit_name}}</p>
      <p class="tips" v-else-if="type == 3 || type==4 ">手续费{{ income_to_yuan_fee_rate }}%</p>
      <div class="h50" v-else></div>
      <van-button block color="#F15353" round @click="confirm">确定</van-button>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      text: "元积分提现",//1-元积分、2-元积分提现配额、3-收益积分、4-收益积分（会员转让）、5-元积分（转入收益积分）、6-收益积分提现
      count: 0,
      type: null,
      uid: "",

      income_to_yuan_fee_rate:"",
      income_name:"",
      yuan_name: "",
      income:"",
       yuan_withdraw_limit_name: "",
      yuan_withdraw_quota: 0,
      usable_yuan: 0,
      open:1,//是否扣除提现配置
    };
  },
  activated() {
    this.type =  Number(this.$route.params.num);
    if(String(this.$route.params.open)){
      this.open = Number(this.$route.params.open);
    }
    this.count = 0;
    this.getData();
  },
  methods: {
    onFocus(){
      if(Number(this.count) == 0 ){
        this.count='';
      }
    },
    getData() {
      let url = "";
      if (this.type == 1 || this.type == 2 || this.type==5 ) {
        url = 'plugin.wise-yuan-trade.frontend.yuan-point.index';
      } else if (this.type == 3|| this.type==4 || this.type==6) {
        url = 'plugin.wise-yuan-trade.frontend.income-point.index';
      }
      $http.get(url, "", "").then(res => {
        if (res.result) {
          let data = res.data;
          if (this.type == 1 || this.type == 2 || this.type==5) {
            if (this.type == 1 ||this.type==5) {
              this.yuan_name = data.yuan_name;
              this.yuan_withdraw_limit_name = data.yuan_withdraw_limit_name;
              this.yuan_withdraw_quota = data.yuan_withdraw_quota;
              this.usable_yuan = data.usable_yuan;
              if(this.type==1){
                this.text = `${data.yuan_name}提现`;
              }else{
                $http.get("plugin.wise-yuan-trade.frontend.income-point.index").then(resdata=>{
                  console.log(resdata,"===");
                  let _data = resdata.data;
                  if(resdata.result!==1){
                    return this.$toast(_data.msg);
                  }
                  this.text = `转入${_data.income_name}`;
                })
              }
            }else {
              this.yuan_withdraw_quota = data.yuan_withdraw_quota;
              this.yuan_withdraw_limit_name = data.yuan_withdraw_limit_name;
              this.text = '会员转让';
            }
          } else {
            this.income=data.income;

            this.income_to_yuan_fee_rate=data.income_to_yuan_fee_rate;
            if(this.type==6){
              this.text = `${data.income_name}提现`;
            }else if(this.type==4){
              this.text="会员转让";
              this.income_to_yuan_fee_rate = data.income_mutual_transfer_fee_rate||0;
            }else{
              this.text = `转入${data.yuan_name}`;
            }
            this.income_name=data.income_name;
          }
        } else {
          this.$toast(res.msg);
        }
      })
    },
    all_handle() {
      if (this.type == 1 || this.type==5) {
        this.count = this.usable_yuan;
      }else if(this.type ==2){
        this.count = this.yuan_withdraw_quota;
      }else{
        this.count = this.income;
      }
    },
    confirm() {
      let url = "", json = { amount: this.count};
      if (this.type == 1) {
        url = 'plugin.wise-yuan-trade.frontend.yuan-point.withdraw';
      } else if (this.type == 2) {
        url = 'plugin.wise-yuan-trade.frontend.yuan-point.yuan-quota-transfer';
        json.uid= this.uid;
      }else if(this.type==4){
        url = 'plugin.wise-yuan-trade.frontend.income-point.mutual-transfer';
        json.uid= this.uid;
      }else if(this.type==5){
        url="plugin.wise-yuan-trade.frontend.yuan-point.yuan-to-income";
      }else if(this.type==6){
        url="plugin.wise-yuan-trade.frontend.income-point.withdraw";
      }else {
        url = 'plugin.wise-yuan-trade.frontend.income-point.to-yuan';
      }
      $http.post(url, json, "").then(res => {
        this.$toast(res.msg);
        if (res.result) {
          this.count = 0;
          this.getData();
        }
      })
    },
  }
};
</script>

<style scoped lang="scss">
.consensus-activity-withdraw {
  padding: 0.625rem 0.75rem;

  .member {
    padding-bottom: 1rem;
    border-bottom: 1px solid #ccc;
    display: flex;
    align-items: center;
    margin-bottom: 1.25rem;

    input {
      border: none;
      margin-left: 0.7813rem;
    }
  }

  .h50 {
    height: 1.5625rem;
  }

  .tips {
    color: #6e6e79;
    font-size: 0.8125rem;
    margin: 0.625rem 0 1.5625rem;
    text-align: left;
  }

  .all {
    color: #f15353;
    font-size: 0.8125rem;
    flex-shrink: 0;
    margin-left: 0.625rem;
  }

  .content {
    display: flex;
    justify-content: space-between;
    padding: 1.3125rem 0 0.9375rem;
    align-items: flex-end;
    border-bottom: 1px solid #ccc;

    input {
      border: none;
      font-size: 1.5rem;
      font-weight: bold;
      width: 100%;
    }
  }

  .fz26 {
    font-size: 0.8125rem;
  }

  .left {
    text-align: left;
  }

  .main {
    margin-top: 0.625rem;
    padding: 0.9375rem 0.7813rem;
    background: #fff;
    border-radius: 0.625rem;
  }

  .head {
    background: #fff;
    border-radius: 0.625rem;
    padding: 1.0938rem 0.75rem;
    text-align: left;
  }
}
</style>
